# Maintainer: J. Peter Mugaas <jpmugaas@suddenlink.net>

_realname=hypothesis
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python2-${_realname}"  "${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
pkgver=4.43.7
pkgrel=1
pkgdesc="Advanced Quickcheck style testing library for Python (mingw-w64)"
arch=('any')
url='https://hypothesis.readthedocs.org'
license=('MIT')
makedepends=("${MINGW_PACKAGE_PREFIX}-python2"
             "${MINGW_PACKAGE_PREFIX}-python3"
             "${MINGW_PACKAGE_PREFIX}-python3-attrs"
             "${MINGW_PACKAGE_PREFIX}-python2-attrs"
             "${MINGW_PACKAGE_PREFIX}-python3-coverage"
             "${MINGW_PACKAGE_PREFIX}-python2-coverage"
             "${MINGW_PACKAGE_PREFIX}-python2-enum34"
             "${MINGW_PACKAGE_PREFIX}-python3-setuptools"
             "${MINGW_PACKAGE_PREFIX}-python2-setuptools")
#checkdepends=("${MINGW_PACKAGE_PREFIX}-python3-pytest-runner"
#              "${MINGW_PACKAGE_PREFIX}-python2-pytest-runner"
#              "${MINGW_PACKAGE_PREFIX}-python3-flake8"
#              "${MINGW_PACKAGE_PREFIX}-python2-flake8"
#              "${MINGW_PACKAGE_PREFIX}-python3-pytz"
#              "${MINGW_PACKAGE_PREFIX}-python2-pytz"
#              "${MINGW_PACKAGE_PREFIX}-python3-numpy"
#              "${MINGW_PACKAGE_PREFIX}-python2-numpy"
#              "${MINGW_PACKAGE_PREFIX}-python3-faker" 
#              "${MINGW_PACKAGE_PREFIX}-python2-faker"
#              "${MINGW_PACKAGE_PREFIX}-python3-flaky"
#              "${MINGW_PACKAGE_PREFIX}-python2-flaky" 
#              "${MINGW_PACKAGE_PREFIX}-python3-pytest-benchmark"
#              "${MINGW_PACKAGE_PREFIX}-python2-pytest-benchmark"
#              "${MINGW_PACKAGE_PREFIX}-python3-django"
#              "${MINGW_PACKAGE_PREFIX}-python2-django"
#              "${MINGW_PACKAGE_PREFIX}-python3-pytest-xdist"
#              "${MINGW_PACKAGE_PREFIX}-python2-pytest-xdist"
#              "${MINGW_PACKAGE_PREFIX}-python3-mock"
#              "${MINGW_PACKAGE_PREFIX}-python2-mock"
#              "${MINGW_PACKAGE_PREFIX}-python3-pandas"
#              "${MINGW_PACKAGE_PREFIX}-python2-pandas")
options=('staticlibs' 'strip' '!debug')
source=("${_realname}-$pkgver.tar.gz"::"https://github.com/HypothesisWorks/hypothesis/archive/hypothesis-python-$pkgver.tar.gz")
sha512sums=('bf074f74b1bf0d79405cb529c4e639794117a28b5e21cd6c86125dee232bb1dfa831ffda15779f46c795c0a31e896d96f0f9f197c40de89e742caca57041f8c2')

# Helper macros to help make tasks easier #
apply_patch_with_msg() {
  for _patch in "$@"
  do
    msg2 "Applying $_patch"
    patch -Nbp1 -i "${srcdir}/$_patch"
  done
}

del_file_exists() {
  for _fname in "$@"
  do
    if [ -f $_fname ]; then
      rm -rf $_fname
    fi
  done
}
# =========================================== #

prepare() {
  cd "${srcdir}"
  sed -i "/FutureWarning/a \    filterwarnings('ignore', category=DeprecationWarning, module='pandas.core')" \
       ${_realname}-${_realname}-python-$pkgver/hypothesis-python/tests/common/setup.py
  for builddir in python{2,3}-build-${CARCH}; do
    rm -rf ${builddir} | true
    cp -r "${_realname}-${_realname}-python-${pkgver}" "${builddir}"
  done
  # Set version for setuptools_scm
  export SETUPTOOLS_SCM_PRETEND_VERSION=$pkgver
  export LC_CTYPE=en_US.UTF-8
}

# Note that build() is sometimes skipped because it's done in 
# the packages setup.py install for simplicity if you can do so.
# but sometimes, you want to do a check before install which would
# also trigger the build.
build() {
  for pver in {2,3}; do  
    msg "Python ${pver} build for ${CARCH}"  
    cd "${srcdir}/python${pver}-build-${CARCH}/hypothesis-python"
    ${MINGW_PREFIX}/bin/python${pver} setup.py build
  done  
}

# Comment out until we can get this to work.
#check() {
#  for pver in {2,3}; do
#    msg "Python ${pver} test for ${CARCH}"
#    cd "${srcdir}/python${pver}-build-${CARCH}/hypothesis-python"
#    mv tests/django ../
#    ${MINGW_PREFIX}/bin/python${pver} setup.py pytest --addopts -n16
#    mv ../django tests/
#    PYTHONPATH="$PWD/build/lib:$PYTHONPATH" ${MINGW_PREFIX}/bin/python${pver} -m tests.django.manage test tests.django || warning "Tests failed"
#
#  done
#}

package_python3-hypothesis() {
  depends=("${MINGW_PACKAGE_PREFIX}-python3"
           "${MINGW_PACKAGE_PREFIX}-python3-attrs"
           "${MINGW_PACKAGE_PREFIX}-python3-coverage")
  optdepends=("${MINGW_PACKAGE_PREFIX}-python3-pytz: for datetime and django module"
              "${MINGW_PACKAGE_PREFIX}-python3-faker: for fakefactory and django module"
              "${MINGW_PACKAGE_PREFIX}-python3-django: for django module"
              "${MINGW_PACKAGE_PREFIX}-python3-numpy: for numpy module"
              "${MINGW_PACKAGE_PREFIX}-python3-pytest: for pytest module")

  cd "${srcdir}/python3-build-${CARCH}/hypothesis-python"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python3 setup.py install --prefix=${MINGW_PREFIX} \
    --root="${pkgdir}" --optimize=1 --skip-build
}

package_python2-hypothesis() {
  depends=("${MINGW_PACKAGE_PREFIX}-python2"
           "${MINGW_PACKAGE_PREFIX}-python2-attrs"
           "${MINGW_PACKAGE_PREFIX}-python2-coverage"
           "${MINGW_PACKAGE_PREFIX}-python2-enum34")
  optdepends=("${MINGW_PACKAGE_PREFIX}-python2-pytz: for datetime and django module"
              "${MINGW_PACKAGE_PREFIX}-python2-faker: for fakefactory and django module"
              "${MINGW_PACKAGE_PREFIX}-python2-django: for django module"
              "${MINGW_PACKAGE_PREFIX}-python2-numpy: for numpy module"
              "${MINGW_PACKAGE_PREFIX}-python2-pytest: for pytest module")

  cd "${srcdir}/python2-build-${CARCH}/hypothesis-python"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python2 setup.py install --prefix=${MINGW_PREFIX} \
    --root="${pkgdir}" --optimize=1 --skip-build
}

package_mingw-w64-i686-python2-hypothesis() {
  package_python2-hypothesis
}

package_mingw-w64-i686-python3-hypothesis() {
  package_python3-hypothesis
}

package_mingw-w64-x86_64-python2-hypothesis() {
  package_python2-hypothesis
}

package_mingw-w64-x86_64-python3-hypothesis() {
  package_python3-hypothesis
}
